import { getGlobalEnv } from "../constants";

const { appTitle } = getGlobalEnv();

export const zConsoleScope = appTitle;

export enum ZConsoleType {
  LOG = "LOG",
  WARN = "WARNING",
  ERROR = "ERROR",
}

// Unified Log output function. Maybe useful to do some log collection and analysis.
export function zConsole(
  msg: string,
  type = ZConsoleType.LOG,
  scope = zConsoleScope
) {
  const content = `[${scope}] ${type}: ${msg}`;
  const print = {
    [ZConsoleType.LOG]: console.log,
    [ZConsoleType.WARN]: console.warn,
    [ZConsoleType.ERROR]: console.error,
  };
  print[type](content);
}

export function zLog(msg: string) {
  zConsole(msg, ZConsoleType.LOG);
}

export function zWarn(msg: string) {
  zConsole(msg, ZConsoleType.WARN);
}

export function zError(msg: string) {
  zConsole(msg, ZConsoleType.ERROR);
}
